package userController

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"go-demo-2025/controllers"
	"go-demo-2025/service/work_wechat"
	"log"
	"net/http"
)

func GetWorkWechatUserInfo(c *gin.Context) {
	// 定义一个 map 来存储请求体中的数据
	var requestData map[string]interface{}

	// 绑定请求体中的 JSON 数据到 map
	if err := c.ShouldBindJSON(&requestData); err != nil {
		log.Printf("Failed to bind JSON: %v", err)
		c.JSON(http.StatusBadRequest, gin.H{"error": "Failed to bind JSON"})
		return
	}

	if requestData["mobile"] == "" {
		controllers.ReturnError(c, 400, fmt.Sprintf("缺少参数mobile"))
		return
	}

	service := work_wechat.NewWorkWechatConfig()
	data, err := service.GetWorkWechatUserInfo(requestData["mobile"].(string))
	if err != nil {
		controllers.ReturnError(c, 400, fmt.Sprintf("获取失败:%v", err))
		return
	}

	controllers.ReturnSuccess(c, 200, "获取成功", data, 1)
}
